
cc.Class({
    extends: cc.Component,

    properties: {
        showSprite:{
            default:null,
            type:cc.Sprite
        },

        frame1:{
            default:null,
            type:cc.SpriteFrame
        },

        frame2:{
            default:null,
            type:cc.SpriteFrame
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },

    // update (dt) {},

    initSwitchButton:function (startState) {
        this.nowState = startState
        if(startState === 1){
            this.showSprite.spriteFrame = this.frame1
        }else if(startState === 2){
            this.showSprite.spriteFrame = this.frame2
        }
    },

    setFrame1Cb:function (cb) {
        this.frame1Cb = cb
    },

    setFrame2Cb:function (cb) {
        this.frame2Cb = cb
    },

    onNodeClicked:function (event) {
        if(this.nowState === 1 && this.frame2Cb){
            this.showSprite.spriteFrame = this.frame2
            this.frame2Cb()
            this.nowState = 2
        }else if(this.nowState === 2 && this.frame1Cb){
            this.showSprite.spriteFrame = this.frame1
            this.frame1Cb()
            this.nowState = 1
        }
    },

});
